package main

import (
	_ "github.com/ClickHouse/clickhouse-go"
	"github.com/jmoiron/sqlx"
	"log"
	"time"
)

func main() {
	connect, err := sqlx.Open("clickhouse", "tcp://192.168.3.34:9000?debug=true")
	if err != nil {
		log.Fatal(err)
	}
	now := time.Now()
	rows, err := connect.Query("SELECT count(*) as num FROM lineorder")
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()
	t := time.Now()
	log.Println(t.Sub(now))
	log.Println(rows.Columns())
	for rows.Next() {
		var num int
		err := rows.Scan(&num)
		if err != nil {
			log.Fatal(err)
		}
		log.Println(num)
		//var (
		//	LO_SHIPMODE string
		//	countShip   string
		//	LO_ORDERPRIORITY    string
		//	countOrder float64
		//)
		//if err := rows.Scan(&LO_SHIPMODE, &countShip, &LO_ORDERPRIORITY, &countOrder); err != nil {
		//	log.Fatal(err)
		//}
		//log.Printf("C_CITY: %v, S_CITY:%v,year:%v,revenue:%v", LO_SHIPMODE, countShip, LO_ORDERPRIORITY, countOrder)
	}
	if err := rows.Err(); err != nil {
		log.Fatal(err)
	}
}
